Skip to content

Conversation

@sme229
Copy link
Owner

@sme229 sme229 commented Feb 24, 2024

FASTQ filter function using biopython and task 5

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кажется у тебя есть гит-репозиторий внутри гит-репозитория

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Раз файл пустой можно удалить:)

from Bio import SeqIO
from Bio.SeqUtils import GC

def filter_fastq(input_path: str, quality_threshold: int, output_filename="final_filtered.fastq", gc_bounds=(40, 60), length_bounds=(50, 350)):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут не хватает докстринги (тем более же что по идее увас они были в прошлом семестре

###GC content filter
min_gc_content = gc_bounds[0]
max_gc_content = gc_bounds[1]
GC_quality_filt = []
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Переменные только с маленькими буквами!

Comment on lines +20 to +21
result_quality = SeqIO.write(GC_quality_filt, "good_quality_GC.fastq", "fastq")
result_quality_GC_length = SeqIO.parse("good_quality_GC.fastq", "fastq")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

С точки зрения использования функционала биопитона - все супер. Но как код организован - не очень хорошо к сожалению. У тебя получается как-то разбросаны проверки, при чем после каждой проверке ты создаешь новый файл на компьютере куда записываешь сиквенсы. Ну и между этими промежутками чтения и записи все файлы ты держишь в памяти. В этом плане все можно было бы организовать гораздо проще и еще и лучше.

Сперва мы открываем файл на запись. После этого мы в цикле for читаем записи из входного файла. На каждой итерации цикла мы держим в памяти одну запись, мы проверяем ее всеми нужными проверками и если все ок - то записыаем в файл. При этом никаких промежуточных файлов в большом количестве не создается.

Псведокод:

with open(output) as outf:
    for seq in SeqIO.parse(input):
        if ok and ok and ok:
            SeqIO.write(seq, outf)

Comment on lines +75 to +76
list_input = list(self.seq)
for i in range(len(self.seq)):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не надо итерироваться по индексам и потом брать [i] если можно сразу делать цикл по буквам

for i in range(len(self.seq)):
if list_input[i] in self.complement_dict:
list_input[i] = self.complement_dict[list_input[i]]
return "".join(list_input)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У тебя получается была ДНК, а после complement стала просто строка. Чтобы тип данных оставался как есть можно сделать:

Suggested change
return "".join(list_input)
return type(self)("".join(list_input))

Если не понимаешь что тут - можем на консультации еще обсудить

complement_dict = {'A': 'T', 'T': 'A', 'G': 'C', 'C': 'G', 'a': 't', 't': 'a', 'g': 'c', 'c': 'g'}
def __init__(self, seq):
super().__init__(seq)
#self.complement()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#self.complement()

Comment on lines +98 to +99
def __init__(self, seq):
super().__init__(seq)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в целом это можно не писать, так как по дефолту инит родителя и будет работать

Comment on lines +77 to +78
if list_input[i] in self.complement_dict:
list_input[i] = self.complement_dict[list_input[i]]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А что если else? Кажется такого быть не может, если при инициализации происходит поверка что все буквы валидны

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants